<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets a server-side timeout for this query</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongocursor.limit.html">« MongoCursor::limit</a></li>
      <li style="float: right;"><a href="mongocursor.next.html">MongoCursor::next »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongocursor.html">MongoCursor</a></li>
    <li>Sets a server-side timeout for this query</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongocursor.maxtimems" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoCursor::maxTimeMS</h1>
  <p class="verinfo">(PECL mongo &gt;=1.5.0)</p><p class="refpurpose"><span class="refname">MongoCursor::maxTimeMS</span> &mdash; <span class="dc-title">Sets a server-side timeout for this query</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongocursor.maxtimems-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>MongoCursor::maxTimeMS</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$ms</code></span>): <span class="type"><a href="class.mongocursor.html" class="type MongoCursor">MongoCursor</a></span></div>

  <p class="para rdfs-comment">
   Specifies a cumulative time limit in milliseconds to be allowed by the server
   for processing operations on the cursor.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongocursor.maxtimems-parameters">
  <h3 class="title">Parameters</h3>
  <dl>

   
    <dt>

     <code class="parameter">ms</code>
    </dt>

    <dd>

     <p class="para">
      Specifies a cumulative time limit in milliseconds to be allowed by the
      server for processing operations on the cursor.
     </p>
    </dd>

      
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongocursor.maxtimems-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   This cursor.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongocursor.maxtimems-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> if this cursor has started
   iterating.
  </p>
  <p class="para">
   Causes methods that fetch results to throw a
   <a href="class.mongoexecutiontimeoutexception.html" class="classname">MongoExecutionTimeoutException</a> if the query takes
   longer than the specified number of milliseconds in processing time.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongocursor.maxtimems-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-150">
   <p><strong>Example #1 <span class="methodname"><strong>MongoCursor::maxTimeMS()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    In the following example, the server will abort the query if the cursor
    requires more than two seconds in processing time to return its results.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$cursor&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">find</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$cursor</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">maxTimeMS</span><span style="color: #007700">(</span><span style="color: #0000BB">2000</span><span style="color: #007700">);<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$results&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">iterator_to_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$cursor</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">MongoExecutionTimeoutException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"query&nbsp;took&nbsp;too&nbsp;long!"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-mongocursor.maxtimems-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
     Unlike <span class="methodname"><a href="mongocursor.timeout.html" class="methodname">MongoCursor::timeout()</a></span>, which specifies a
     client-side timeout, <span class="methodname"><strong>MongoCursor::maxTimeMS()</strong></span> can be
     used to cause the MongoDB server to abort long-running queries. This
     timeout is cumulative for the lifetime of the cursor (i.e. each batch will
     contribute to this time limit). The timeout only considers processing time;
     idle time is not considered.
   </p>
  </div>
 </div>


</div></div></div></body></html>